package com.blacktea.structuralpatterns.decoratorpattern.service;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @description: 跑步计时装饰器接口实现
 * @author: black tea
 * @date: 2023/3/22 17:01
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class RunServiceTimeDecorator implements RunServiceDecorator {

    private final RunService runService;

    private TimeInterval timer = null;

    @Override
    public void startRun() {
        runService.startRun();
    }

    @Override
    public void endRun() {
        runService.endRun();
    }

    @Override
    public void startRunTime() {
        timer = DateUtil.timer();
        this.startRun();
    }

    @Override
    public void endRunTime() {
        this.endRun();
        log.info("本次跑步，耗费了:{}毫秒", timer.intervalRestart());
    }
}
